﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PNProject.EF;
using PNProject.Core;

namespace PNProject.Core.Converter
{
    public class LinkConverter
    {
        public static Link ToLink(LinkModel link)
        {
            Link obj = new Link();
            try
            {
                obj.LinkID = link.LinkID;
                obj.TextLink = link.TextLink;
                obj.URL = link.URL;
                obj.Image = link.Image;
                obj.Lang = link.Lang;
                obj.Type = link.Type;
                return obj;
            }
            catch (Exception e)
            {
                return new Link();
            }
        }

        public static Link CopyLink(Link link)
        {
            Link obj = new Link();
            try
            {
                obj.LinkID = link.LinkID;
                obj.TextLink = link.TextLink;
                obj.URL = link.URL;
                obj.Image = link.Image;
                obj.Lang = link.Lang;
                obj.Type = link.Type;
                return obj;
            }
            catch (Exception e)
            {
                return new Link();
            }
        }

        public static LinkModel LinkTo(Link link)
        {
            LinkModel obj = new LinkModel();
            obj.LinkID = link.LinkID;
            obj.TextLink = link.TextLink;
            obj.URL = link.URL;
            obj.Image = link.Image;
            obj.Lang = link.Lang.HasValue ? link.Lang.Value : false;
            obj.Type = link.Type.HasValue ? link.Type.Value : false;
            return obj;
        }
    }
}